package flash;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.ToolBarContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import com.akeil.flash.action.AdvancedSettingAction;
import com.akeil.flash.action.BaseSettingAction;
import com.akeil.flash.action.ConnectAction;
import com.akeil.flash.action.StartTestAction;
import com.akeil.flash.action.StopTestAction;
import com.akeil.flash.statusline.ContributionPool;
import com.akeil.flash.statusline.GreenTextStatusLineContributionItem;
import com.akeil.flash.statusline.ImageStatusLineContributionItem;
import com.akeil.flash.statusline.TextLineContributionItem;
import com.akeil.flash.utils.ShowToolBarText;
import com.akeil.flash.utils.StatusTimerManager;

/**
 * An action bar advisor is responsible for creating, adding, and disposing of
 * the actions added to a workbench window. Each window will be populated with
 * new actions.
 */
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

	// Actions - important to allocate these only in makeActions, and then use
	// them
	// in the fill methods. This ensures that the actions aren't recreated
	// when fillActionBars is called with FILL_PROXY.
	
	IAction startTestAction = null;
	IAction stopTestAction = null;
	IAction baseSettingAction = null;
	IAction advancedSettingAction = null;
	IAction connectAction = null;
	IAction preferencesAction = null;
	IWorkbenchAction resetPerspectiveAction  = null;
	TextLineContributionItem sampletemperatureInfo = null;
	TextLineContributionItem desktopInfo = null;
	ImageStatusLineContributionItem serialInfo = null;
	GreenTextStatusLineContributionItem deviceInfo = null;

	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
		super(configurer);
	}

	@Override
	protected void makeActions(IWorkbenchWindow window) {
		// TODO 自动生成的方法存根
		super.makeActions(window);
		
		preferencesAction = ActionFactory.PREFERENCES.create(window);
		register(preferencesAction);
		
		startTestAction = new StartTestAction();
		stopTestAction = new StopTestAction();
		baseSettingAction = new BaseSettingAction();
		advancedSettingAction = new AdvancedSettingAction();
		connectAction = new ConnectAction();
		
		resetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE.create(window);
	    register(resetPerspectiveAction);
	}

	@Override
	protected void fillMenuBar(IMenuManager menuBar) {
		// TODO 自动生成的方法存根
		super.fillMenuBar(menuBar);
		
		MenuManager windowMenu = new MenuManager("系统(&W)", "Manager");
		windowMenu.add(resetPerspectiveAction);
		windowMenu.add(preferencesAction);
		windowMenu.add(advancedSettingAction);
		
		menuBar.add(windowMenu);
	}

	@Override
	protected void fillCoolBar(ICoolBarManager coolBar) {
		// TODO 自动生成的方法存根
		super.fillCoolBar(coolBar);
		IToolBarManager controlBar = new ToolBarManager(coolBar.getStyle());
		controlBar.add(startTestAction);
		controlBar.add(stopTestAction);
		controlBar.add(baseSettingAction);
		controlBar.add(connectAction);
		controlBar.add(new ShowToolBarText());
		coolBar.add(new ToolBarContributionItem(controlBar, "project"));
	}

	@Override
	protected void fillStatusLine(IStatusLineManager statusLine) {
		// TODO 自动生成的方法存根
		super.fillStatusLine(statusLine);
		
		sampletemperatureInfo = new TextLineContributionItem("sampletemperatureInfo", 150);
		sampletemperatureInfo.setText("样品温度");
		sampletemperatureInfo.setVisible(true);
		ContributionPool.getInstance().setContrbution("sampletemperatureInfo",sampletemperatureInfo);
		
		desktopInfo = new TextLineContributionItem("desktopInfo", 150);
		desktopInfo.setText("底座温度");
		desktopInfo.setVisible(true);
		ContributionPool.getInstance().setContrbution("desktopInfo",desktopInfo);
		
		serialInfo = new ImageStatusLineContributionItem("counterInfo", 100);
		serialInfo.setText("联机");
		serialInfo.setVisible(true);
		ContributionPool.getInstance().setContrbution("serialInfo",serialInfo);
		
		deviceInfo = new GreenTextStatusLineContributionItem("deviceInfo", 100);
		deviceInfo.setText("检测结束");
		deviceInfo.setVisible(true);
		ContributionPool.getInstance().setContrbution("deviceInfo", deviceInfo);
		
		statusLine.add(sampletemperatureInfo);
		statusLine.add(desktopInfo);
		statusLine.add(deviceInfo);
		statusLine.add(serialInfo);
		
		Application.statusTimerManager = StatusTimerManager.getInstance(deviceInfo);
	}
	
	
}
